//优化前
function fun(arr) {
    for (let i = 1; i < arr.length ; i++) {
        for (let j = 0; j < arr.length; j++) {
            if (arr[j] > arr[j + 1]) {
                [arr[j],arr[j+1]] = [arr[j+1],arr[j]]
            }
        }
    }
    console.log(arr)
}
fun([ 1, 5, 8, 7, 6, 3, 4, 9])

function trr(arr) {
    for (let i = 0; i < arr.length ; i++) {
        for (let j = 0; j < arr.length -1 -i; j++) {
            if (arr[j] > arr[j + 1]) {
                [arr[j],arr[j+1]] = [arr[j+1],arr[j]]
            }
        }
    }
    console.log(arr)
}
trr([ 1, 5, 8, 7, 6, 3, 4, 9])